﻿@model IContentModelBase
@{
    ViewBag.Title = "Edit content";

    // add js
    Html.AddToBackEndContent("~/Areas/Proggy/Content/Scripts/Proggy.ContentEdit.js", BackEndContentType.JavaScript);

    // get allowed list
    var allowedTemplates = (IEnumerable<SelectListItem>)ViewBag.AllowedTemplates;

    // get type data
    var typeData = Model.GetTypeData();

    // get tabs
    var tabs = typeData.Tabs;

    // set parent model (for _TabInner)
    ViewBag.ParentModel = Model; 
}
<h2>@ViewBag.Title</h2>
<div class="proggy-edit-div">
    @using (Html.BeginForm("Edit", "Content", FormMethod.Post, new { enctype = "multipart/form-data" }))
    { 
        <div class="proggy-save-bar">
            <input type="submit" class="proggy-button-go" value="Save" />
            |
            @Html.ActionLink("Return to content", "Index", new { selected = Model.Id }, new { @class = "proggy-button-stop" })
            | @Html.ActionLink("Preview", "Preview", new { id = Model.Id }, new { @class = "proggy-button proggy-content-preview", target = "_blank" })
            | @Html.ActionLink("Publish now >>", "Publish", new { id = Model.Id }, new { @class = "proggy-button proggy-content-publish" })
        </div> 
        @Html.Raw(HttpUtility.HtmlDecode(Html.ValidationSummary(false).ToHtmlString()))
        <div id="tabs-moved">
            <h3 data-tab="Core">
                Core
            </h3>
            @foreach (var tab in tabs)
            { 
                <h3 data-tab="@tab.Name">@tab.Name</h3>
            }
            @Html.Clear()
        </div>
        <div id="tabs-inner-moved">
            <div class="tab-inner" data-tab="Core">
                @Html.HiddenFor(m => m.TypeAlias)
                @Html.HiddenFor(m => m.Id)
                @Html.HiddenFor(m => m.IsRoot)
                <h4>
                    1. @Html.LabelFor(m => m.Name)
                </h4>
                <div class="property-editor left-indent">
                    @Html.TextBoxFor(m => m.Name, new { @class = "proggy-textbox proggy-textbox-wide" })
                </div>
                @{
            //
            var uniqueAliasNumber = 3;    
                }
                @if (!Model.IsRoot)
                {
                    <h4>
                        2. @Html.LabelFor(m => m.UrlSlug)
                    </h4>
                    <div class="property-editor left-indent">
                        @Html.TextBoxFor(m => m.UrlSlug, new { @class = "proggy-textbox proggy-textbox-wide", maxlength = "50" })
                    </div>
                }
                else
                {
                    //
                    uniqueAliasNumber = 2;

                    //
                    @:@Html.HiddenFor(m => m.UrlSlug)
                                }
                <h4>
                    @(uniqueAliasNumber++). @Html.LabelFor(m => m.UniqueAlias)</h4>
                <div class="property-editor left-indent">
                    @Html.TextBoxFor(m => m.UniqueAlias, new { @class = "proggy-textbox proggy-textbox-wide" })
                </div>
                <h4>@uniqueAliasNumber. @Html.LabelFor(m => m.Template)</h4>
                <div class="property-editor left-indent">
                    @Html.DropDownListFor(m => m.Template, allowedTemplates)
                </div>
            </div>
            @foreach (var tab in tabs)
            {
                Html.RenderPartial("_TabInner", tab);
            }
        </div>           
        <div class="proggy-save-bar proggy-save-bar-bottom">
            <input type="submit" class="proggy-button-go" value="Save" />
            |
            @Html.ActionLink("Return to content", "Index", new { selected = Model.Id }, new { @class = "proggy-button-stop" })
            | @Html.ActionLink("Preview", "Preview", new { id = Model.Id }, new { @class = "proggy-button proggy-content-preview", target = "_blank" })
            | @Html.ActionLink("Publish now >>", "Publish", new { id = Model.Id }, new { @class = "proggy-button proggy-content-publish" })
        </div>                                                                                  
    }
</div>
<script type="text/javascript">
    jQuery(function () {
        var editor = new Proggy.ContentEdit();
        editor.Init();
    });
</script>
